package com.atguigu.eduService.controller;


import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.vo.CourseInfoVo;
import com.atguigu.eduService.vo.CoursePublishVo;
import com.atguigu.eduService.vo.CourseQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Chen Wen bo
 * @since 2021-07-22
 */
@Api(tags = "课程管理")
@RestController
@RequestMapping("/eduService/course")
@CrossOrigin
public class EduCourseController {

    @Resource
    private EduCourseService eduCourseService;

    @ApiOperation("添加课程基本信息")
    @PostMapping("/addCourseInfo")
    public Result<Map<String,String>> addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        String id = eduCourseService.addCourseInfo(courseInfoVo);
        Map<String,String> map = new HashMap<>();
        map.put("id",id);
        return ResultUtil.success(map);
    }

    @ApiOperation("根据课程id查询课程基本信息")
    @GetMapping("/getCourseInfo/{courseId}")
    public Result<CourseInfoVo> getCourseInfo(@PathVariable String courseId){
        CourseInfoVo courseInfoVo = eduCourseService.getCourseInfo(courseId);
        return ResultUtil.success(courseInfoVo);
    }

    @ApiOperation("修改课程信息")
    @PutMapping("/updateCourseInfo")
    public Result<CourseInfoVo> updateCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
        eduCourseService.updateCourseInfo(courseInfoVo);
        return ResultUtil.success();
    }

    @ApiOperation("根据课程id查询课程确认信息")
    @GetMapping("/getPublishCourseInfo/{id}")
    public Result<CoursePublishVo> getPublishCourseInfo(@PathVariable String id){
        CoursePublishVo courseInfoVoList = eduCourseService.getPublishCourseInfo(id);
        return ResultUtil.success(courseInfoVoList);
    }

    @ApiOperation("课程最终发布")

    @PutMapping("/publishCourse/{id}")
    public Result<EduCourse> publishCourse(@PathVariable String id){
        eduCourseService.publishCourse(id);
        return ResultUtil.success();
    }

    @ApiOperation("条件查询课程列表")
    @PostMapping("/getCoursePageList/{current}/{size}")
    public Result<IPage<EduCourse>> getCoursePageList(@PathVariable @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                                          @PathVariable @ApiParam(name = "size", value = "每页记录数", required = true) Long size,
                                                          @RequestBody(required = false) CourseQueryVo courseQueryVo){
        return ResultUtil.success(eduCourseService.getCoursePageList(current, size, courseQueryVo));
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/deleteCourse/{courseId}")
    public Result<EduCourse> deleteCourse(@PathVariable String courseId){
        eduCourseService.deleteCourse(courseId);
        return ResultUtil.success();
    }

}

